function ZYLXMaterialProperty(options) {
    this._definitionChanged = new Cesium.Event()
    this._image = undefined
    this._imageSubscription = undefined
    this._color = undefined
    // this._colorSubscription = undefined
    this._repeat = undefined
    this._repeatSubscription = undefined
    this._duration = undefined
    this._durationSubscription = undefined
    this._highlight = undefined
    this._highlightSubscription = undefined

    this.image = options.image
    this.color = options.color
    this.repeat = options.repeat
    this.duration = options.duration
    this.time = new Date().getTime()
    this.highlight = options.highlight
}

Object.defineProperties(ZYLXMaterialProperty.prototype, {
    isConstant: {
        get: function() {
            return (
                Cesium.Property.isConstant(this._image) && Cesium.Property.isConstant(this._repeat)
            )
        }
    },
    definitionChanged: {
        get: function() {
            return this._definitionChanged
        }
    },
    image: Cesium.createPropertyDescriptor('image'),
    // color: Cesium.createPropertyDescriptor('color'),
    repeat: Cesium.createPropertyDescriptor('repeat'),
    duration: Cesium.createPropertyDescriptor('duration'),
    highlight: Cesium.createPropertyDescriptor('highlight')
})
ZYLXMaterialProperty.prototype.getType = function(time) {
    return 'ZYLXMaterial'
}
ZYLXMaterialProperty.prototype.getValue = function(time, result) {
    if (!Cesium.defined(result)) {
        result = {}
    }
    result.image = Cesium.Property.getValueOrUndefined(this._image, time)
    result.color = this.color // 防抖
    // result.color = Cesium.Property.getValueOrClonedDefault(
    //     this.color,
    //     time,
    //     Cesium.Color.WHITE,
    //     result.color
    // )
    result.repeat = Cesium.Property.getValueOrClonedDefault(
        this._repeat,
        time,
        11,
        result.repeat
    )
    result.duration = Cesium.Property.getValueOrClonedDefault(
        this._duration,
        time,
        2000,
        result.duration
    )
    result.time =
		((new Date().getTime() - this.time) % this.duration) / this.duration
    result.highlight = Cesium.Property.getValueOrClonedDefault(
        this._highlight,
        time,
        false,
        result.highlight
    )
    return result
}
ZYLXMaterialProperty.prototype.equals = function(other) {
    return (
        this === other ||
		(other instanceof ZYLXMaterialProperty &&
			Cesium.Property.equals(this._image, other._image) &&
			Cesium.Property.equals(this._color, other._color) &&
			Cesium.Property.equals(this._repeat, other._repeat) &&
			Cesium.Property.equals(this._duration, other._duration) &&
			Cesium.Property.equals(this._highlight, other._highlight))
    )
}
Cesium.ZYLXMaterialProperty = ZYLXMaterialProperty

Cesium.Material._materialCache.addMaterial('ZYLXMaterial', {
    fabric: {
        type: 'ZYLXMaterial',
        uniforms: {
            color: new Cesium.Color(1.0, 0.0, 0.0, 0.5),
            image: '/assets/images/arrow.png',
            time: 0,
            repeat: 1,
            highlight: false
        },
        source: `
				uniform vec4 color;
				uniform float time;
				uniform float repeat;
				uniform sampler2D image;
				czm_material czm_getMaterial(czm_materialInput materialInput)
				{
					czm_material material = czm_getDefaultMaterial(materialInput);
					vec2 st = materialInput.st;
					vec4 colorImage = texture2D(image, vec2(fract(st.s*repeat-time*1.0), st.t));
					material.alpha =colorImage.a;
					float time = fract(czm_frameNumber * 0.03);
					material.diffuse = colorImage.rgb  ;
					return material;
				}`
    },
    translucent: function(material) {
        return material.uniforms.color.alpha < 1.0
    }
})
export default ZYLXMaterialProperty
